local gangjitielv = fk.CreateSkill{
    name = "rmt__gangjitielv",
}
Fk:loadTranslationTable{
    ["rmt__gangjitielv"] = "钢纪铁律",
    [":rmt__gangjitielv"] = "你的回合内，其他角色弃置牌后，你使用其中一张。其他角色获得牌后，你观看其的手牌并获得其中一张。你受到伤害后，本回合内也可发动此技能。",
    ["#rmt__gangjitielv-use"] = "钢纪铁律：使用其中一张牌",
}

gangjitielv:addEffect(fk.AfterCardsMove, {
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(gangjitielv.name) and (player == player.room.current or #player.room.logic:getActualDamageEvents(1, function(e)
            return e.data.to == player
        end) > 0) then
            local ids = {}
            local room = player.room
            for _, move in ipairs(data) do
                if move.toArea == Card.DiscardPile then
                    if move.moveReason == fk.ReasonDiscard and move.from and move.from ~= player then
                        for _, info in ipairs(move.moveInfo) do
                            if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
                            room:getCardArea(info.cardId) == Card.DiscardPile then
                                table.insertIfNeed(ids, info.cardId)
                            end
                        end
                    end
                else
                    if move.to ~= player and move.toArea == Card.PlayerHand and move.to:getHandcardNum() > 0 then
                        event:setCostData(self, {value = 2, to = move.to})
                        return true
                    end
                end
            end
            ids = player.room.logic:moveCardsHoldingAreaCheck(ids)
            if #ids > 0 then
                event:setCostData(self, {value = 1, cards = ids})
                return true
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local cost_data = event:getCostData(self)
        if cost_data.value == 1 then
            local use = room:askToUseRealCard(player, {
                pattern = cost_data.cards,
                cancelable = false,
                expand_pile = cost_data.cards,
                extra_data = {
                    bypass_times = true,
                    extraUse = true,
                },
                skill_name = gangjitielv.name,
                prompt = "#rmt__gangjitielv-use",
                skip = true,
            })
            if use then
                event:setCostData(self, {value = 1, use = use})
                return true
            end
        else
            return cost_data.to:getHandcardNum() > 0
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cost_data = event:getCostData(self)
        if cost_data.value == 1 then
            room:useCard(cost_data.use)
        else
            local id = room:askToChooseCard(player,{
                target = cost_data.to,
                flag = { card_data = { {"$Hand", cost_data.to:getCardIds("h")} } },
                skill_name = gangjitielv.name,
            })
            room:obtainCard(player, id, false, fk.ReasonJustMove, player, gangjitielv.name)
        end
    end,
})

return gangjitielv